<?php
  $path = 'san_pham/nhap_xuat/nhap_hang_hoi';
  $class = 'nhap-hang-hoi';
  if ($data['type'] == 'nhap hang nguyen'){
  $path = 'san_pham/nhap_xuat/nhap_hang_nguyen';
  $class = 'nhap-hang-nguyen';
}
  $i = 0;
?>
<form method="post" action="<?php echo base_path() . $path ?>" id="nhap-hang-hoi" class="<?php echo $class ?>">
  <div class="form-item form-select-wrapper khach-hang-wrapper">
    <label for="txt-khach-hang">Khách hàng</label>
    <input id="txt-khach-hang" value="<?php echo ($_POST && $_POST['khach-hang']) ? $_POST['khach-hang'] : '' ?>"
           name="khach-hang" type="text"
           class="form-text form-autocomplete text txt-khach-hang <?php echo ($_POST && (string) $_POST['error']['key'] == 'khach-hang')
             ? 'error' : '' ?>" autocomplete="OFF"/>
    <input class="autocomplete" type="hidden" id="txt-khach-hang-autocomplete"
           value="<?php echo base_path() . 'khach_hang/autocomplete' ?>" disabled="disabled"/>
  </div>
  <div class="clear"></div>
  <fieldset>
    <legend>Nhập số lượng thành phẩm</legend>
    <div id="form-item-wrapper">
      <?php if ($_POST && isset($_POST['ten_vat_tu'])) { ?>
      <?php foreach ($_POST['ten_vat_tu'] as $key => $ten_vat_tu) { ?>
        <?php $i++; ?>
        <div class="form-item-row">
          <div class="form-item form-text-wrapper">
            <label for="txt-ten-vat-tu-<?php echo $i ?>">Tên sản phẩm</label>
            <input id="txt-ten-vat-tu-<?php echo $i ?>" value="<?php echo $ten_vat_tu ?>" name="ten_vat_tu[]"
                   type="text"
                   class="form-text form-autocomplete text txt-ten-vat-tu <?php echo ($_POST['error']['key'] == $key && isset($_POST['error']['ten_vat_tu']))
                     ? 'error' : '' ?>" autocomplete="OFF"/>
            <?php if ($i > 1) { ?>
            <input class="autocomplete" type="hidden" id="txt-ten-vat-tu-<?php echo $i ?>-autocomplete"
                   value="<?php echo base_path() . 'san_pham/autocomplete' ?>" disabled="disabled"/>
            <?php } ?>
          </div>
          <div class="form-item">
            <input id="field-remove-submit-<?php echo $i ?>" type="button" value="X"
                   class="field-remove-submit form-submit"/>
          </div>
          <div class="form-item form-text-wrapper">
            <label for="txt-so-luong-<?php echo $i ?>">Số lượng<?php echo (($data['type'] == 'nhap hang hoi') ? ' được BH' : '') ?></label>
            <input id="txt-so-luong-<?php echo $i ?>" value="<?php echo $_POST['so_luong'][$key] ?>" name="so_luong[]"
                   type="text"
                   class="form-text text txt-so-luong <?php echo ($_POST['error']['key'] == $key && isset($_POST['error']['so_luong']))
                     ? 'error' : '' ?>" autocomplete="OFF"/>
          </div>
          <?php if ($data['type'] == 'nhap hang hoi') { ?>
           <div class="form-item form-text-wrapper">
             <label for="txt-gia-tien-<?php echo $i ?>">Số lượng hồi</label>
             <input id="txt-gia-tien-<?php echo $i ?>" value="<?php echo $_POST['gia_tien'][$key] ?>" name="gia_tien[]" type="text" class="form-text text txt-gia-tien <?php echo ($_POST['error']['key'] == $key && isset($_POST['error']['gia_tien'])) ? 'error' : '' ?>" autocomplete="OFF" />
           </div>
          <?php }?>
          <div class="clear"></div>
        </div>
        <?php } ?>
      <?php } else { ?>
      <?php $i++; ?>
      <div class="form-item-row">
        <div class="form-item form-text-wrapper">
          <label for="txt-ten-vat-tu-1">Tên sản phẩm</label>
          <input id="txt-ten-vat-tu-1" name="ten_vat_tu[]" type="text"
                 class="form-text form-autocomplete text txt-ten-vat-tu" autocomplete="OFF"/>
        </div>
        <div class="form-item">
          <input id="field-remove-submit-1" type="button" value="X" class="field-remove-submit form-submit"/>
        </div>
        <div class="form-item form-text-wrapper">
          <label for="txt-so-luong-1">Số lượng<?php echo (($data['type'] == 'nhap hang hoi') ? ' được BH' : '') ?></label>
          <input id="txt-so-luong-1" name="so_luong[]" type="text" class="form-text text txt-so-luong" autocomplete="OFF"/>
        </div>
        <?php if ($data['type'] == 'nhap hang hoi') { ?>
            <div class="form-item form-text-wrapper">
              <label for="txt-gia-tien-1">Số lượng hồi</label>
              <input id="txt-gia-tien-1" name="gia_tien[]" type="text" class="form-text text txt-gia-tien" autocomplete="OFF" />
            </div>
          <?php } ?>
        <div class="clear"></div>
      </div>
      <?php } ?>
    </div>
    <div id="add-more-wrapper">
      <input id="add-more-vat-tu" type="button" value="Thêm sản phẩm" class="field-add-more-submit form-submit"/>
    </div>
  </fieldset>
  <div class="form-item form-textarea-wrapper">
    <label for="ghi-chu">Ghi chú</label>
    <textarea id="ghi-chu" name="ghi_chu"
              class="form-textarea <?php echo ($_POST && (string) $_POST['error']['key'] == 'ghi_chu') ? 'error'
                : '' ?>" cols="60" rows="5"><?php echo ($_POST) ? $_POST['ghi_chu'] : '' ?></textarea>

    <div class="description">Nhập tối đa 500 ký tự. Số lượng hiện thời: <span style="color: red;"
                                                                              id="ghi-chu-length">0</span></div>
  </div>
  <div id="submit-wrapper">
    <input class="autocomplete" type="hidden" id="txt-ten-vat-tu-1-autocomplete"
           value="<?php echo base_path() . 'san_pham/autocomplete' ?>" disabled="disabled"/>
    <input type="hidden" id="total-post" value="<?php echo $i  ?>" disabled="disabled"/>
    <input id="submit" type="submit" onclick="return check_thanh_pham();" value="Nhập dữ liệu" class="form-submit"/>
<!--    <input id="submit" type="submit" value="Nhập dữ liệu" class="form-submit" style="display: none;"/>-->
  </div>
</form>